package org.grayrabbit.cms.util;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
 
public class HqlUtil {
    public static final String NUM_1="1";
    public static final int SHOW_TYPE_LENGTH=6;
	
	/**
	 * @param objs
	 * @return     ( 'a','2','t','4' )  
	 */
	public static String arraysToString(String[] objs){
		StringBuffer sb = new StringBuffer();
		if(objs != null && objs.length != 0 ){
			sb.append(" ( ");
			for(int i=0;i<objs.length;i++){
				sb.append("'").append(objs[i]).append("'");
				if(i != objs.length-1)
					sb.append(",");
			}
			sb.append(" ) "); 
		}
		return sb.toString();
	} 
	
	/** flag 第几位是“1” 
	 * @param flag
	 * @return
	 */
	public static List<Integer> splitFlagIndex(String flag){
		if(StringUtils.isBlank(flag)) return null;
		if(flag.length() >SHOW_TYPE_LENGTH){
			flag=flag.substring(0,SHOW_TYPE_LENGTH);
		}  
		List<Integer> list = new ArrayList<Integer>();
		for(int i=0;i<flag.length();i++){
			if(NUM_1.equals(flag.charAt(i)+"")){
				list.add((i+1));
			}
		}
		return list;
	}
 
}
